package com.lyy.photovoltaic.controller;

import com.alibaba.fastjson.JSONObject;
import com.lyy.photovoltaic.beans.Notice;
import com.lyy.photovoltaic.common.vo.ResultVO;
import com.lyy.photovoltaic.service.NoticeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping("/notice")
@Api(value = "公告新闻接口", tags = "公告新闻管理")
public class NoticeController {
    @Autowired
    NoticeService noticeService;
    @PostMapping(value = "/add")
    public ResultVO addNotice(@RequestBody JSONObject jsonObject) {
        ResultVO resultVO = noticeService.addNotice(jsonObject);
        return resultVO;
    }
    @GetMapping(value = "/visible")
    public ResultVO allVisibleNotices() {
        ResultVO resultVO = noticeService.allVisibleNotices();
        return resultVO;
    }

    @GetMapping(value = "/findNoticesByPages")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "int", name = "currentPageNum", value = "分页页码", required = true),
            @ApiImplicitParam(dataType = "int", name = "pageSize", value = "分页页面大小", required = true)
    })
    public ResultVO findNoticesByPages(@RequestParam("currentPageNum") int pageNum,@RequestParam("pageSize") int pageSize) {
//        System.out.println(pageNum+"------"+pageSize);
        ResultVO resultVO = noticeService.findNoticesByPages(pageNum,pageSize);
        return resultVO;
    }
    @GetMapping(value = "/visibleNoticeCount")
    public int VisibleNoticeCount() {
        int i = noticeService.VisibleNoticeCount();
        return i;
    }
    @GetMapping(value = "/{noticeId}")
    @ApiImplicitParam(dataType = "string", name = "noticeId", value = "根据noticeId查询信息", required = true)
    public ResultVO findNoticeById(@PathVariable("noticeId") String nId) {
//        System.out.println(nId);
        ResultVO noticeById = noticeService.findNoticeById(nId);
        return noticeById;
    }
    @DeleteMapping(value = "/{noticeId}")
    @ApiImplicitParam(dataType = "string", name = "noticeId", value = "根据noticeId删除公告信息", required = true)
    public ResultVO deleteNoticeById(@PathVariable("noticeId") String nId) {
//        System.out.println(nId);
        ResultVO noticeById = noticeService.deleteNoticeById(nId);
        return noticeById;
    }
    @PutMapping(value = "/{noticeId}")
    @ApiImplicitParam(dataType = "string", name = "noticeId", value = "根据noticeId修改信息", required = true)
    public ResultVO updateNotice(@RequestBody Notice notice) {
//        System.out.println(nId);
        ResultVO noticeById = noticeService.updateNotice(notice);
        return noticeById;
    }
    @GetMapping(value = "/allNotice")
    public ResultVO allNotice() {
//        System.out.println(nId);
        ResultVO resultVO = noticeService.allNotice();
        return resultVO;
    }
}
